﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConjureBivouac2012.World;
using ConjureBivouac2012.Object;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace ConjureBivouac2012
{
    public class GameInfo
    {
        private ContentManager contentManager;
        private GraphicsDevice device;
        private static GameInfo gameInfo;
        private Dictionary<PlayerIndex, AbstractPlayer> players;
        //private List<AbstractEnemy> enemies;
        private WorldMap world;

        private float _survivedTime;

        private GameInfo()
        {
        }

        public float SurvivedTime
        {
            get { return _survivedTime; }
        }

        public static GameInfo GetInstance()
        {
            if (gameInfo == null)
            {
                gameInfo = new GameInfo();
            }
            return gameInfo;
        }

        public void Initialize(ContentManager contentManager, GraphicsDevice device)
        {
            this.contentManager = contentManager;
            this.device = device;
            _survivedTime = 0;

            world = new WorldMap(device.Viewport.Width, device.Viewport.Height, 10);

            players = new Dictionary<PlayerIndex, AbstractPlayer>();
            //players.Add(PlayerIndex.One, new PlayerDeflecter(PlayerIndex.One));

            //foreach (AbstractPlayer player in players.Values)
            //{
            //    player.Initialize();
            //    player.LoadContent(contentManager);
            //}

            //enemies = new List<AbstractEnemy>();
            //AbstractEnemy e = new BasicEnemy(1,1);
            
            //enemies.Add(e);
            
            //foreach (AbstractEnemy enemy in enemies)
            //{
            //    enemy.Initialize();
            //    enemy.LoadContent(contentManager);
            //}

            //e.sprite.setPosition(400, 400);
            //e.setVelocity(new Vector2(20, 20));
            //e.SetDirection(new Vector2(0.8f, 0.8f));
        }

        public void Execute(GameTime gameTime)
        {
            if (Program.GetGameInstance.IsActive)
            {
                //foreach (AbstractPlayer player in players.Values)
                //{
                //    player.Update(gameTime);
                //}

                //foreach (AbstractEnemy enemy in enemies)
                //{
                //    enemy.Update(gameTime);
                //}

                _survivedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
        }

        public void Draw(SpriteBatch theSpriteBatch)
        {
            //foreach (AbstractPlayer player in players.Values)
            //{
            //    player.Draw(theSpriteBatch);
            //}

            //foreach (AbstractEnemy enemy in enemies)
            //{
            //    enemy.Draw(theSpriteBatch);
            //}
        }

        public Dictionary<PlayerIndex, AbstractPlayer> GetPlayers()
        {
            return players;
        }

        public ContentManager GetContent()
        {
            return contentManager;
        }

        public GraphicsDevice GetDevice()
        {
            return device;
        }
    }
}
